package com.igoal.admin.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.igoal.admin.web.model.AdminBaseModel;
import com.igoal.admin.web.model.AdminManageGoalsModel;
import com.igoal.dto.CategoryDTO;
import com.igoal.dto.GoalDTO;

@Controller
public class AdminManageGoalsController extends AdminBaseController {

	@RequestMapping(method=RequestMethod.GET, value="/admin/manageGoals.html")
	public String show(ModelMap modelMap, HttpServletRequest request){
		AdminManageGoalsModel model = new AdminManageGoalsModel();
		
		initLeftPage(model, request);
		initRightPage(model, request);
		
		applyModel(modelMap, model);
		
		return getViewPrefix() + "manageGoals";		
	}
	
	@Override
	public void initLeftPage(AdminBaseModel baseModel, HttpServletRequest request) {
	}

	@Override
	public void initRightPage(AdminBaseModel baseModel, HttpServletRequest request) {
		AdminManageGoalsModel model = (AdminManageGoalsModel) baseModel;
		
		List<GoalDTO> goals = goalManager.getAllGoals();
		model.setGoals(goals);
		
		List<CategoryDTO> categories = categoryManager.getAllCategories();
		model.setCategories(categories);
	}
	
}
